/**
 * v-numberFloatOnly 只允许输入数字及2位小数
 * Copyright (c) 2019 ruoyi
 */

export default {
  bind(el) {
    el.handler = function (event) {
      const input = event.target;
      input.value = input.value
        .replace(/[^\d.]/g, "")
        .replace(/^\./g, "")
        .replace(/\.{2,}/g, ".")
        .replace(".", "$#$")
        .replace(/\./g, "")
        .replace("$#$", ".")
        .replace(/^(\-)*(\d+)\.(\d\d).*$/, "$1$2.$3");
    };
    el.addEventListener("input", el.handler);
  },
  unbind(el) {
    el.removeEventListener("input", el.handler);
  },
};
